﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Puzzler.Plugin.Interface.Attributes
{
    internal static class AttributeUtils
    {
        public static T ExtractSingleAttribute<T>(Type baseType, bool inherited)
        {
            object[] attributes = baseType.GetCustomAttributes(typeof(T), inherited);
            if (attributes.Length != 1)
                throw new IndexOutOfRangeException("No attribute or too many attributes was found of attribute type '" +
                                                   typeof(T).Name + "' on type '" + baseType.Name + "'!");

            return (T) attributes[0];
        }
    }
}
